package com.easybacklog.client;

import com.easybacklog.client.cucumberfeatures.BacklogFeaturesList;
import com.easybacklog.client.cucumberfeatures.ProductBacklogView;
import com.easybacklog.client.model.Project;
import com.easybacklog.client.sourcefeatures.SourceFeaturesList;
import com.easybacklog.client.sourcefeatures.SourceFeaturesView;
import com.easybacklog.client.webservices.LoadFeatureFiles;
import com.easybacklog.client.webservices.subversion.RequestGetSubversionSpecificationFile;
import com.google.gwt.user.client.ui.VerticalPanel;

public class InitializeEasyBacklog {

	public static VerticalPanel vpBacklog = new VerticalPanel();

	public static VerticalPanel getBacklogPanel(String projectID,
			String userID, String projectType, String projectURL) {

		EasyBacklogGlobalVariables.userID = userID;

		Project project = new Project(projectID, projectType, projectURL);

		EasyBacklogGlobalVariables.currentProject = project;

		loadSpecificationFile();

		new LoadFeatureFiles();

		vpBacklog.clear();

		vpBacklog.add(new EasyBacklogPage());

		return vpBacklog;
	}

	private static void loadSpecificationFile() {

		if (Project.REPOSITORY_TYPE_SUBVERSION
				.equals(EasyBacklogGlobalVariables.currentProject
						.getRepositoryType())) {

			RequestGetSubversionSpecificationFile.loadJSONFile();

		} else if (Project.REPOSITORY_TYPE_GIT
				.equals(EasyBacklogGlobalVariables.currentProject
						.getRepositoryType())) {

		} else if (Project.REPOSITORY_TYPE_LOCAL
				.equals(EasyBacklogGlobalVariables.currentProject
						.getRepositoryType())) {

		}
	}

	public static void reInitialize() {

		InitializeEasyBacklog.vpBacklog.clear();
		InitializeEasyBacklog.vpBacklog.add(new EasyBacklogPage());

		ProductBacklogView.vpProjectBacklog.clear();
		ProductBacklogView.vpProjectBacklog.add(new BacklogFeaturesList());

		SourceFeaturesView.vpSourceFeatures.clear();
		SourceFeaturesView.vpSourceFeatures.add(new SourceFeaturesList());
	}
}
